package com.example.managementjava.course;

import com.example.managementjava.Student.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/Servlet_Cou")
public class Servlet_Cou extends HttpServlet {
    public static List<Course> Coulist = new ArrayList<>();
    @Override
    public void init(){
        Coulist = DB_Cou.selectAlllist();
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        //这里类型要设置未text/json
        resp.setContentType("text/json;charset=utf-8");
        PrintWriter out = resp.getWriter();

        out.println(Coulist.size());
        for (Course i : Coulist){
            out.println(i.toString());
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }


}
